<?php

    function _tvn_cart_validate($data) {
        if (empty($data['shipping_address_id'])) {
            return t('Please choose address to shipping.');
        }
        if (empty($data['shipping_method'])) {
            return t('Please get shipping rates and choose shipping method.');
        } else {
            return '';
        }
    }

    function _tvn_cart_insert_data($table, $data) {
        return db_insert($table)->fields($data)->execute();
    }

    function tvn_cart_copy_row_address_book($aid) {
        $address = _tvn_cart_address_book_by_id($aid);
        unset($address['aid']);
        return _tvn_cart_insert_data('tvn_users_address_book_order', $address);
    }

    function _tvn_cart_address_book_by_id($aid) {
        return db_select('tvn_users_address_book', 'a')->fields('a')->condition('a.aid', $aid)->execute()->fetchAssoc();
    }
